DamerauLevenshtein

class DamerauLevenshtein(val insertionWeight: Double = Constants.DEFAULT_WEIGHT, val deletionWeight: Double = Constants.DEFAULT_WEIGHT, val substitutionWeight: Double = Constants.DEFAULT_WEIGHT, val transpositionWeight: Double = Constants.DEFAULT_WEIGHT) : MetricStringDistance, StringSimilarity, StringDistance(source)

Implements the Damerau-Levenshtein distance (Damerau, 1964) with transposition (also sometimes calls unrestricted Damerau-Levenshtein distance). It is the minimum number of operations needed to transform one string into the other, where an operation is defined as an insertion, deletion, or substitution of a single character, or a transposition of two adjacent characters. It does respect triangle inequality, and is thus a metric distance.

This is not to be confused with the optimal string alignment distance, which is an extension where no substring can be edited more than once.

The similarity is computed as \(\frac{w_d \lvert X \rvert + w_i \lvert Y \rvert - distance(X, Y)}{2}\).

References

Damerau, F. J. (1964-03). A technique for computer detection and correction of spelling errors. Communications of the ACM, 7(3), 171-176. https://doi.org/10.1145/363958.363994[sci-hub]

Author

solonovamax

Parameters

insertionWeight

The weight of an insertion. Represented as \(w_i\). Must be in the range \([0, 1 \times 10^{10} ]\).

deletionWeight

The weight of a deletion. Represented as \(w_d\). Must be in the range \([0, 1 \times 10^{10} ]\).

substitutionWeight

The weight of a substitution. Represented as \(w_s\). Must be in the range \([0, 1 \times 10^{10} ]\).

transpositionWeight

The weight of a substitution. Represented as \(w_t\). Must be in the range \([0, 1 \times 10^{10} ]\).

See also

Constructors

Link copied to clipboard
constructor(insertionWeight: Double = Constants.DEFAULT_WEIGHT, deletionWeight: Double = Constants.DEFAULT_WEIGHT, substitutionWeight: Double = Constants.DEFAULT_WEIGHT, transpositionWeight: Double = Constants.DEFAULT_WEIGHT)

Properties

Link copied to clipboard

The weight of a deletion. Represented as \(w_d\).

Link copied to clipboard

The weight of an insertion. Represented as \(w_i\).

Link copied to clipboard

The weight of a substitution. Represented as \(w_s\).

Link copied to clipboard

The weight of a transposition. Represented as \(w_t\).

Functions

Link copied to clipboard
open override fun distance(s1: String, s2: String): Double

Compute and return the metric distance.

Link copied to clipboard
open override fun similarity(s1: String, s2: String): Double

Computes the similarity of two strings.